<?php if (!defined('BASEPATH'))exit('No direct script access allowed');
/**
 * 网站资讯模块控制器
 */
class News extends MY_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('content_model');
        $this->load->model('cate_model');
    }
    
    
    //关于我们
    function index($cate_id) {
        
        $where = array();
        $where['group'] = 'news';//网站资讯
        $where['id'] = $cate_id;
        $cate = $this->cate_model->content_cate_get($where);
        if(!$cate){redirect('news/16');}
        $where = array();
        $where['cate_id'] = $cate['id'];
        $where['status'] = 1;
        $records_per_page = 8;
        //总数
        $getCount = $this->content_model->get_count($where);
        $page = new Paging($getCount,$records_per_page);
        $list = $this->content_model->get_list($where,(($page->get_page() - 1) * $records_per_page),$records_per_page);
        foreach ($list as $key=>$val){
            
            $list[$key]['day'] = date('d',$val['create_time']);
            $list[$key]['month'] = date('Y.m',$val['create_time']);
            $list[$key]['url'] = site_url('news/'.$cate_id.'/'.$val['id']);
            $list[$key]['summary'] = mb_substr($val['summary'], 0, 93, 'utf-8')."...";
        }
        $this->assign('list', $list);
        $this->assign('showPage', $page->showpage());
        $this->assign('cate',$cate);
        $this->assign('action',$cate['code']);
        $this->display('news/index.html');
    }
    function detail($cate_id,$content_id){
        $where = array();
        $where['group'] = 'news';//网站资讯
        $where['id'] = $cate_id;
        $cate = $this->cate_model->content_cate_get($where);
        $cate['url'] = site_url('news/'.$cate_id);
        $item = $this->content_model->get(array('id'=>$content_id,'status'=>1,'cate_id'=>$cate_id));
        $item ? '' : redirect('news/16');//判断是否存在次文章
        $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
        //$item['content'] = strstr($item['content'],"http://") ?  : str_replace('<img src="', '<img src="'.$this->img_url, $item['content']);
        $this->assign('item', $item);
        $this->assign('cate', $cate);
        $this->assign('action',$cate['code']);
        $this->display('news/detail.html');
    }
}
